package Acme.Serve;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletInputStream;

class ServeInputStream extends ServletInputStream {

	private InputStream in;

	public ServeInputStream(InputStream in) {
		this.in = in;
	}

	public int readLine(byte[] b, int off, int len) throws IOException {
		int off2 = off;
		while (off2 - off < len) {
			int r = read();
			if (r == -1) {
				if (off2 == off)
					return -1;
				break;
			}
			if (r == 13)
				continue;
			if (r == 10)
				break;
			b[off2] = (byte) r;
			++off2;
		}
		return off2 - off;
	}

	public int read() throws IOException {
		return in.read();
	}

	public int read(byte[] b, int off, int len) throws IOException {
		return in.read(b, off, len);
	}

	public int available() throws IOException {
		return in.available();
	}

	public void close() throws IOException {
		in.close();
	}

}